import io.opentracing.Tracer;
import io.opentracing.mock.MockSpan;
import io.opentracing.mock.MockTracer;
import io.opentracing.tag.Tags;

import java.util.Map;
import java.util.concurrent.TimeUnit;

public class test {
    public static void main(String[] args) {
        MockTracer tracer = new MockTracer();

        // Create a new Span, representing an operation.
        MockSpan span = tracer.buildSpan("foo").start();


        // Add a tag to the Span.
        span.setTag(Tags.COMPONENT, "my-own-application");
        span.setTag(Tags.DB_INSTANCE,"customers");  //测试 span tag
        span.setTag("db.instance","cddustomers");   //测试 span tag
        span.log("testlog");
        span.setBaggageItem("bkey","baggageMsg");

        System.out.println(String.format("spanId = %s ",span.context().spanId()));
        System.out.println(String.format("parentId = %s",span.parentId()));

        System.out.println("span2 ceshi ====================");
        {

            MockSpan span2 = tracer.buildSpan("fo2").start();
            span2.setTag(Tags.COMPONENT,"my-own2");
            
            System.out.println(String.format("parentId = %s",span2.parentId()));

            span2.finish();
        }
        System.out.println("span2 ceshi ====================");

        // Finish the Span.
        span.finish();



        // Analize the saved Span.
        System.out.println("Operation name = " + span.operationName());
        System.out.println("Start = " + span.startMicros());
        System.out.println("Finish = " + span.finishMicros());
        System.out.println("Finish = " + (span.finishMicros()-span.startMicros())/(1000*1000));
        System.out.println(span.getBaggageItem("bkey"));

        // Inspect the Span's tags.
        Map<String, Object> tags = span.tags();
        System.out.println(tags);
    }
}
